﻿package PinballCode {
	import flash.display.Shape;
	
	// Triangle class
	public class Triangle extends Shape {
		
		private var a:Vertex;			// point a of triangle
		private var b:Vertex;			// point b of triangle
		private var c:Vertex;			// point c of triangle
		private var color;				// color of shape
		private var thickness;			// thickness of lines
		public var walls:Array;
		private var hypo:Wall;			
		
		// constructor
		public function Triangle(a:Vertex, b:Vertex, c:Vertex, left:Boolean, color:uint = 0x0000FF, thickness:int = 1) {
			// constructor code
			walls = new Array();
			this.a = a;
			this.b = b;
			this.c = c;
			if(left) {
				walls.push(new Wall(b,a));
				walls.push(new Wall(c,b));
				walls.push(new Wall(a,c));
			}
			else
			{
				walls.push(new Wall(a,b));
				walls.push(new Wall(b,c));
				walls.push(new Wall(c,a));
			}
			this.color = color;
			this.thickness = thickness;
			for each(var wall in walls)
			{
				if(wall.distance < hypo)
					hypo = wall;
			}
			init();
		}
		
		// Initiates the Triangle and redraws it
		public function init() {
			graphics.clear();
			graphics.beginFill(color);
			graphics.lineStyle(thickness, color);
			graphics.moveTo(a.x, a.y);
			graphics.lineTo(b.x, b.y);
			graphics.lineTo(c.x, c.y);
			graphics.lineTo(a.x, a.y);			
			graphics.endFill();
		}

	}
	
}
